﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using IFRS.DataAccess.DAL;
using IFRS.Models;

namespace IFRS.DataAccess.DAL
{
    public class SPR_ROLEGROUPUSER
    {
        public DataTable SEARCH_ALL(RoleGroupUser rolegroupuser, Paging paging,string COST_CENTER_NM, ref int iRecordCount)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting));
                lstParams.Add(new SqlParameter("@RoleGroupID", rolegroupuser.RoleGroupID.AsDBValue()));
                lstParams.Add(new SqlParameter("@COST_CENTER_NM", COST_CENTER_NM.AsDBValue()));
                lstParams.Add(new SqlParameter("@IsActive", rolegroupuser.IsActive.AsDBValue()));
                dt = Utility.StoredProcDataTable("SPR_ROLEGROUPUSER_SEARCHALL", lstParams.ToArray());

                iRecordCount = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public DataTable SEARCH_BYID(int RoleGroupUserID)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RoleGroupUserID", RoleGroupUserID));
                dt = Utility.StoredProcDataTable("SPR_ROLEGROUPUSER_SEARCHBYID", lstParams.ToArray());

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public int INSERT(RoleGroupUser vRoleGroupUser)
        {

            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();

            try
            {
                lstParams.Add(new SqlParameter("@RoleGroupUserID", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@EmployeeCode", vRoleGroupUser.EmployeeCode));
                lstParams.Add(new SqlParameter("@Username", vRoleGroupUser.Username));
                lstParams.Add(new SqlParameter("@RoleGroupID", vRoleGroupUser.RoleGroupID));
                lstParams.Add(new SqlParameter("@IsActive", vRoleGroupUser.IsActive));
                lstParams.Add(new SqlParameter("@CreatedDate", vRoleGroupUser.CreatedDate));
                lstParams.Add(new SqlParameter("@CreatedBy", vRoleGroupUser.CreatedBy));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", vRoleGroupUser.CreatedCostCenter));
                lstParams.Add(new SqlParameter("@CreatedBranch", vRoleGroupUser.CreatedBranch));
                lstParams.Add(new SqlParameter("@UpdatedDate", vRoleGroupUser.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", vRoleGroupUser.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", vRoleGroupUser.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", vRoleGroupUser.UpdatedBranch));

                Utility.ExecuteStoredProc("SPR_ROLEGROUPUSER_INSERT", lstParams.ToArray());

                iNum = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int UPDATE(RoleGroupUser vRoleGroupUser)
        {


            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RoleGroupUserID", vRoleGroupUser.RoleGroupUserID));
                lstParams.Add(new SqlParameter("@EmployeeCode", vRoleGroupUser.EmployeeCode));
                lstParams.Add(new SqlParameter("@Username", vRoleGroupUser.Username));
                lstParams.Add(new SqlParameter("@RoleGroupID", vRoleGroupUser.RoleGroupID));
                lstParams.Add(new SqlParameter("@IsActive", vRoleGroupUser.IsActive));
                lstParams.Add(new SqlParameter("@CreatedDate", vRoleGroupUser.CreatedDate));
                lstParams.Add(new SqlParameter("@CreatedBy", vRoleGroupUser.CreatedBy));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", vRoleGroupUser.CreatedCostCenter));
                lstParams.Add(new SqlParameter("@CreatedBranch", vRoleGroupUser.CreatedBranch));
                lstParams.Add(new SqlParameter("@UpdatedDate", vRoleGroupUser.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", vRoleGroupUser.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", vRoleGroupUser.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", vRoleGroupUser.UpdatedBranch));
                iNum = (int)Utility.ExecuteStoredProc("SPR_ROLEGROUPUSER_UPDATE", lstParams.ToArray());

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int DELETE(RoleGroupUser vRoleGroupUser)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RoleGroupUserID", vRoleGroupUser.RoleGroupUserID));
                lstParams.Add(new SqlParameter("@UpdatedDate", vRoleGroupUser.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", vRoleGroupUser.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", vRoleGroupUser.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", vRoleGroupUser.UpdatedBranch));
                iNum = (int)Utility.ExecuteStoredProc("SPR_ROLEGROUPUSER_DELETE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }


    }
}
